package com.wanglin.test

import java.io.*

fun main() {
    val file= File("D:\\rfzn\\resource\\08demo\\dpspProcess\\dpsp\\src\\com\\wanglin\\test\\dimens.xml")

    val file2= File("D:\\rfzn\\resource\\08demo\\dpspProcess\\dpsp\\src\\com\\wanglin\\test\\dimens2.xml")
    if (!file2.exists())
    {
        file2.createNewFile()
    }


    val br=BufferedReader( FileReader(file))
    val bw=BufferedWriter(FileWriter(file2))

    br.forEachLine {
        if (it.contains("name"))
        {
            val start=  it.indexOf(">")+1
            val end  =it.indexOf("</")-2
            if (start!=-1 && end!=-1)
            {
                val str= it.substring(start,end)
                val dp=Integer.parseInt(str)
                val dp2=dp/2.0
                val newStr=it.replaceRange(start,end,dp2.toString())
                bw.appendLine(newStr)

            }

        }
        else
        {
            bw.appendLine(it)
        }

        bw.flush()
    }


    bw.close()
    br.close()


}